//
//  THRequestVo.m
//  THBaseApp
//
//  Created by TryHone on 16/6/3.
//  Copyright © 2016年 TryHone. All rights reserved.
//

#import "JFRequestVo.h"
#import "JFStringHelper.h"
#import "JFNetRequestHelper.h"
@implementation JFRequestVo

TRYHONE_CODER_DECODER();
TRYHONE_COPY_WITH_ZONE();
TRYHONE_DESCRIPTION();

-(instancetype)init{
    self=[super init];
    if (self) {
        self.isDebug = NO;
        self.cacheType = CacheType_Net;
        self.isPost = YES;
        self.security = YES;
        self.allowInvalidCertificates = YES;//允许不信任的证书
        self.validatesDomainName = NO;//不校验域名
        self.cerCheckMode = CerCheckMode_None;//客户端无条件地信任服务器端返回的证书
        self.forwardErrorCode = YES;
        self.isBackInMain = YES;
    }
    return self;
}
-(void)setIsPost:(BOOL)isPost{
    _isPost = isPost;
    if (_isPost) {
        _methodtype = MethodType_Post;
    }else{
        _methodtype = MethodType_Get;
    }
}
-(NSString*)url{
    if([JFStringHelper isEmpty:self.baseUri]){
        return _url;
    }else if ([JFStringHelper isEmpty:self.path]){
        return _baseUri;
    }else{
        if([JFStringHelper string:_baseUri endWith:@"/"]){
            NSString * url = [NSString stringWithFormat:@"%@%@",_baseUri,_path];
            url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:@"#%^{}\"[]|\\<> "].invertedSet];
//            url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            return url;
        }else{
            NSString * url = [NSString stringWithFormat:@"%@/%@",_baseUri,_path];
//            url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:@"#%^{}\"[]|\\<> "].invertedSet];
              return url;
        }
    }
}
-(BOOL)isDebug{
    if (JFNetRequestHelper.isDebug) {//全局是调试模式
        return _isDebug;//返回接口数据
    }else{
        return false;//全局非调试 不处理接口设置
    }
}
@end
